package com.vgemv.jsutilitysdk.Reminder;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.annotation.StringRes;

import com.vgemv.jsutilitysdk.R;


public class JsLoadingReminderStandard1 extends LinearLayout {

    private ProgressBar mProgressBar;
    private TextView mTv;
    private ImageView mIv;
    private Context mContext;

    public JsLoadingReminderStandard1(Context context) {
        this(context, null);
    }

    public JsLoadingReminderStandard1(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public JsLoadingReminderStandard1(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        this.mContext = context;
        init();
    }

    private void init() {
        //从xml中加载其根元素,然后作为本身的一个子视图.
        View view = LayoutInflater.from(mContext).inflate(R.layout.gaj_loading_reminder_standard_1, this, true);
        mProgressBar = view.findViewById(R.id.progressBar);
        mTv = findViewById(R.id.tv);
        mIv = findViewById(R.id.iv);
    }

    /**
     * loading
     */
    public void showLoading() {
        mIv.setVisibility(GONE);
        mProgressBar.setVisibility(VISIBLE);
    }

    /**
     * 成功
     */
    public void showSuccess() {
        mIv.setImageResource(R.mipmap.load_success);
        mIv.setVisibility(View.VISIBLE);
        mProgressBar.setVisibility(GONE);
    }

    /**
     *失败
     */
    public void showFail() {
        mIv.setImageResource(R.mipmap.load_fail);
        mIv.setVisibility(View.VISIBLE);
        mProgressBar.setVisibility(GONE);
    }

    /**
     * 提示文字
     *
     * @param txt string
     */
    public void setText(String txt) {
        mTv.setText(txt);
    }

    /**
     * 提示文字
     */
    public void setText(@StringRes int txtId) {
        mTv.setText(txtId);
    }
}
